//
//  IMUser.h
//  IMSecurity
//
//  Created by infosec2013 on 16/6/14.
//  Copyright © 2016年 IF. All rights reserved.
//

#import <Foundation/Foundation.h>
@class IMCert;
@class IMToken;

typedef NS_ENUM(NSInteger,UserType)
{
    UserTypeCert = 0,
    UserTypeToken,
    UserTypeTokenAndCert,
};

typedef NS_ENUM(NSInteger,CertAlgType){
    CertAlgTypeSM2WithSM3,
    CertAlgTypeRSAWithMD5,
    CertAlgTypeRSAWithSHA1,
    CertAlgTypeRSAWithSHA256,
    CertAlgTypeRSAWithSHA512,
    CertAlgTypeUnknown,
};

typedef NS_ENUM(NSInteger,SendRegistCodeChannel){
    
    SendRegistCodeChannelNone,
    SendRegistCodeChannelMobile,
    SendRegistCodeChannelEmail,
};

@interface IMUser : NSObject
@property(nonatomic,strong)NSString *username;
@property(nonatomic,strong)NSString *realname;
@property(nonatomic,strong)NSString *companyid;
@property(nonatomic,strong)NSString *mobile;
@property(nonatomic,readonly,strong)IMToken *token;
@property(nonatomic,readonly,strong)IMCert *cert;
@property(nonatomic,readonly,assign)UserType userType;

//本地所有用户的第一个，不存在用户时，返回nil
+ (instancetype)shareUser;

/**
 以用户名初始化的用户对象

 @param username 用户名
 @return 本地存在此用户，返回用户对象，本地不存在用户，返回nil，用户未注册时应使用init进行初始化
 */
+ (instancetype)userWithUserName:(NSString *)username;

/// 服务端注册用户
/// @param userName 用户名
/// @param userType 用户类型     UserTypeCert ,UserTypeToken,UserTypeTokenAndCert,
/// @param phoneNum 手机号
/// @param realName 姓名
/// @param email 邮箱号
/// @param channel 下发注册码方式
/// @param completeBlock 完成后执行block
+ (void)registWithUsername:(NSString *)userName
                  userType:(UserType)userType
                  PhoneNum:(NSString *)phoneNum
                  realName:(NSString *)realName
                     email:(NSString *)email
           sendCodeChannel:(SendRegistCodeChannel)channel
          andCompleteBlock:(void(^)(int resultCode))completeBlock;

/**
 *  用户签约
 *
 *  @param username      用户名
 *  @param signCode      签约码
 *  @param completeBlock 完成后回调block
 */
+ (void)signUpWithUserName:(NSString *)username
                  signCode:(NSString *)signCode
          andCompleteBlock:(void(^)(int resultCode, IMUser *user))completeBlock;

- (void)applyCertAndSeedWithPIN:(NSString *)PIN
               andCompleteBlock:(void(^)(int resultCode))completeBlock;

- (void)updateCertAndSeedWithPIN:(NSString *)PIN
                          newPIN:(NSString *)newPIN
                andCompleteBlock:(void(^)(int resultCode))completeBlock;

- (void)getUserStateWithCompleteBlock:(void(^)(int resultCode, NSDictionary *userState))completeBlock;


/**
 *  解锁用户
 *
 *  @param lockTrade     解锁码
 *  @param completeBlock 解锁完成后回调block
 */
- (void)unlockUserWithLockTrade:(NSString *)lockTrade andCompleteBlock:(void(^)(int resultCode))completeBlock;

- (BOOL)deleteUser;
@end
